package com.haizhi.crm.api.controller.sys.message;

import com.haizhi.crm.api.constant.MediaType;
import com.haizhi.crm.common.model.Response;
import com.haizhi.crm.sys.auth.model.UserQo;
import com.haizhi.crm.sys.message.model.MessageSettingVo;
import com.haizhi.crm.sys.message.service.MessageSettingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by wangshan on 2018/5/15.
 */
@Api(description = "[业务-消息设置]消息设置增删改查" )
@RestController
@RequestMapping("/message/setting" )
public class MessageSettingController {

    @Autowired
    private MessageSettingService messageSettingService;


    @ApiOperation(value = "获取消息设置列表", notes = "输入：userId" )
    @GetMapping("/list" )
    public Response query(@ModelAttribute UserQo userQo) {
        List<MessageSettingVo> messageSettingVos = messageSettingService.query(userQo.getUserId());
        return Response.success(messageSettingVos);
    }

    @ApiOperation(value = "初始化用户消息设置", notes = "输入：userId" )
    @GetMapping(path = "/init" )
    public Response initUser(@ModelAttribute UserQo userQo) {
        messageSettingService.initUser(userQo.getUserId());
        return Response.success();
    }

    @ApiOperation(value = "更新用户消息设置", notes = "输入：messageSettingVos" )
    @PostMapping(path = "/upsert", consumes = MediaType.APP_JSON, produces = MediaType.APP_JSON)
    public Response saveOrUpdate(@RequestBody List<MessageSettingVo> messageSettingVos) {
        messageSettingService.saveOrUpdate(messageSettingVos);
        return Response.success();
    }

    @ApiOperation(value = "保存用户消息设置", notes = "输入：messageSettingVos" )
    @PostMapping(path = "/save", consumes = MediaType.APP_JSON, produces = MediaType.APP_JSON)
    public Response save(@RequestBody List<MessageSettingVo> messageSettingVos) {
        messageSettingService.save(messageSettingVos);
        return Response.success();
    }


    @ApiOperation(value = "删除用户消息设置", notes = "输入：userId" )
    @DeleteMapping(path = "/delete" )
    public Response delete(@ModelAttribute UserQo userQo) {
        messageSettingService.delete(userQo.getUserId());
        return Response.success();
    }


}
